const app = getApp()
const $api = require('../../utils/api.js').API;

Page({
    data:{
        info:{},
        role:0,
        collecttrue:false,
        date: '2020-12-01',
        time: '10:00',
        sendTimeShow:false,
        interviewShow:false,
        showcontact:false,
        requestShow:true,
        imgUrl:app.globalData.imgUrl,
        vipType:false,
        vipId:0,
        seeNum:0
    },

    onLoad: function(e){
        this.setData({
            role:wx.getStorageSync('role')
        })
        this.getVipType(e.uid)
        this.getInfo(e.uid)
    },
    getVipType:function(uid){
        var data = {
            'uid':wx.getStorageSync('uid')
        }
        var that = this
        $api.get('vip/lable',data).then(res =>{
            console.log(res)
            //请求成功
            if(res.data.code == 1){
                that.setData({
                    vipType:true,
                    vipId:res.data.data.id,
                    seeNum:res.data.data.count
                })
                that.getSee(uid);
                that.getinterview(uid);
            }
            //that.getInfo(uid);
        })
    },
    getInfo:function(uid){
        var data = {
            'uid':uid
        }
        var that = this
        $api.get('memberInfo/info',data).then(res => {
            //请求成功
            if(res.data.code == 1){
                that.setData({
                    info:res.data.data
                })
                that.getcollect(res.data.data.id);
                // that.getinterview(uid);
                // that.getSee(uid);
            }
        })
    },
    getSeeType:function(){
        var that = this
        var key ='toSelectlook'
        if(this.data.seeNum > 0){
            wx.showModal({
                title: '提示',
                content: '您是白金VIP会员,可以享受直接查看电话的权限,是否使用？',
                showCancel: true,//是否显示取消按钮
                cancelText:"否",//默认是“取消”
                cancelColor:'skyblue',//取消文字的颜色
                confirmText:"是",//默认是“确定”
                confirmColor: 'skyblue',//确定文字的颜色
                success: function (res) {
                   if(res.cancel) {
                        that.numDec(key);
                   }else{
                        that.vipSee(key)
                   }
                }
             })
        }else{
            this.numDec(key);
        }
    },
    getSee:function(uid){
        var that = this;
        var data = {
            'company_uid':wx.getStorageSync('uid'),
            'uid':uid,
        }
        $api.get('phoneSee/is_see',data).then(res => {
            //请求成功
            if(res.data.code == 1){
                if(res.data.data.type == 2){
                    that.setData({
                        showcontact:true,
                    })
                }else{
                    that.setData({
                        showcontact:false,
                        requestShow:false
                    })
                }
            }else{
                that.setData({
                    showcontact:false,
                    requestShow:true
                })
            }
        })
    },
    //收藏简历
    collectRresume:function(){
        var that = this;
        var data = {
            'uid':wx.getStorageSync('uid'),
            'rid':this.data.info.id,
            'type':3
        }
        $api.post('collection/add',data).then(res => {
            //请求成功
            if(res.data.code == 1){
                wx.showToast({
                    title:'简历收藏成功!!!',
                    duration:3000,
                    mask:true,
                    icon:'none', 
                })
                that.setData({
                    collecttrue:true
                })
            }
        }).catch(err => {
            //请求失败
            console.log('member','请求失败');
        })
    },
    //查询当前简历是否被收藏
    getcollect:function(id){
        var data = {
            'uid':wx.getStorageSync('uid'),
            'rid':id,
            'type':3
        }
        var that = this
        $api.get('collection/info',data).then(res => {
            //请求成功
            if(res.data.code == 1){
                that.setData({
                    collecttrue:true
                })
            }
        })
    },
    //查询当前用户是否邀请过
    getinterview:function(uid){
        var data = {
            'company_uid':wx.getStorageSync('uid'),
            'uid':uid,
        }
        var that = this
        $api.get('interview/is_inter',data).then(res => {
            //请求成功
            if(res.data.code == 1){
                that.setData({
                    interviewShow:true
                })
            }
        }).catch(err => {
            //请求失败
            console.log('member','请求失败');
        })
    },
    submit:function(){
        var that = this
        var data = {
            'company_uid':wx.getStorageSync('uid'),
            'uid':this.data.info.uid,
            'date':this.data.date,
            'time':this.data.time
        }
        $api.post('interview/interViewAdd',data).then(res => {
            //请求成功
            if(res.data.code == 1){
                wx.showToast({
                    title:'面试邀请发送成功!!!',
                    duration:3000,
                    mask:true,
                    icon:'none', 
                })
                that.setData({
                    interviewShow:true,
                    sendTimeShow:false
                })
            }
        })
    },
    interview:function(){
        this.setData({
            sendTimeShow:true
        })
    },
    fail:function(){
        this.setData({
            sendTimeShow:false
        })
    },
    bindDateChange: function(e) {
        this.setData({
          date: e.detail.value
        })
      },
    bindTimeChange: function(e) {
        this.setData({
            time: e.detail.value
        })
    },
    online:function(){
        var id = this.data.info.uid
        wx.navigateTo({
            url: '/pages/message/online/toCompany?touid='+id
        })
    },
    toSelectlook:function(){
        var that = this
        var data = {'company_uid':wx.getStorageSync('uid'),'uid':this.data.info.uid}
        $api.post('phoneSee/add',data).then(res => {
            //请求成功
            if(res.data.code == 1){
                wx.showToast({
                    title:'请求成功,待求职者同意之后即可查看!',
                    duration:3000,
                    mask:true,
                    icon:'none', 
                })
                that.setData({
                    showcontact:false,
                    requestShow:false
                })
            }
        })
    },
    onShareAppMessage: function(){
        return {
            title: "天意美业直通车",
            path: "/pages/index/index?puid="+wx.getStorageSync('uid')
        };
    },
    getVip:function(e){
        var key = e.currentTarget.dataset.key;
        if(this.data.vipType){
            this.numDec(key);
            //this[key]()
        }else{
            wx.showToast({
                title:'请购买VIP会员服务',
                duration:3000,
                mask:true,
                icon:'none',
                success:function(){
                    setTimeout(function(){
                        wx.navigateTo({
                            url: '/pages/vip/index'
                        })
                    },3000) //延迟时间 这里是
                }
            })
        }
        // //查询当前 是否购买了会员服务
        // var that = this
        // var data = {
        //     'company_uid':wx.getStorageSync('uid'),
        //     'uid':this.data.info.uid
        //     }
        // $api.get('vip/is_buy',data).then(res => {
        //     //请求成功
        //     if(res.data.code == 1){
        //         this[key]()
        //     }else{
        //         wx.showToast({
        //             title:'VIP已过期',
        //             duration:3000,
        //             mask:true,
        //             icon:'none',
        //             success:function(){
        //                 setTimeout(function(){
        //                     wx.navigateTo({
        //                         url: '/pages/vip/index'
        //                     })
        //                 },3000) //延迟时间 这里是
        //             }
        //         })
        //     }
        // })
    },
    vipSee:function(key){
        var that = this
        var data = {
            'company_uid':wx.getStorageSync('uid'),
            'uid':this.data.info.uid,
            'vipId':this.data.vipId
        }
        $api.post('vip/numDec',data).then(res =>{
            //请求成功
            if(res.data.code == 1){
                var data = {
                    'company_uid':wx.getStorageSync('uid'),
                    'uid':that.data.info.uid
                }
                $api.post('phoneSee/vipAdd',data).then(res => {
                //请求成功
                    if(res.data.code == 1){
                        that.setData({
                            showcontact:true
                        })
                    }
                })
            }else{
                wx.showToast({
                    title:'系统错误',
                    duration:3000,
                    mask:true,
                    icon:'none'
                })
            }
        })
    },
    numDec:function(key){
        var that = this
        var data = {
            'company_uid':wx.getStorageSync('uid'),
            'uid':this.data.info.uid,
            'vipId':this.data.vipId
        }
        $api.post('vip/numDec',data).then(res =>{
            //请求成功
            if(res.data.code == 1){
                that[key]()
            }else{
                wx.showToast({
                    title:'系统错误',
                    duration:3000,
                    mask:true,
                    icon:'none'
                })
            }
        })
    },
    jump:function(){
        wx.navigateTo({
            url: '/pages/vip/index'
        })
    }
});